package com.openbravo.pos.payment;

import com.openbravo.editor.JEditorKeys;
import com.openbravo.editor.JEditorString;
import com.openbravo.editor.JEditorStringNumber;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.LuhnAlgorithm;
import java.awt.BorderLayout;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PaymentPanelType extends JPanel
  implements PaymentPanel
{
  private double m_dTotal;
  private String m_sTransactionID;
  private JPaymentNotifier m_notifier;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel6;
  private JLabel jLabel7;
  private JLabel jLabel8;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel jPanel4;
  private JPanel jPanel5;
  private JEditorStringNumber m_jCardNumber;
  private JEditorStringNumber m_jExpirationDate;
  private JEditorString m_jHolderName;
  private JEditorKeys m_jKeys;

  public PaymentPanelType(JPaymentNotifier paramJPaymentNotifier)
  {
    this.m_notifier = paramJPaymentNotifier;
    initComponents();
    this.m_jHolderName.addPropertyChangeListener("Edition", new RecalculateName( ));
    this.m_jCardNumber.addPropertyChangeListener("Edition", new RecalculateName( ));
    this.m_jExpirationDate.addPropertyChangeListener("Edition", new RecalculateName( ));
    this.m_jHolderName.addEditorKeys(this.m_jKeys);
    this.m_jCardNumber.addEditorKeys(this.m_jKeys);
    this.m_jExpirationDate.addEditorKeys(this.m_jKeys);
  }

  public JComponent getComponent()
  {
    return this;
  }

  public void activate(String paramString, double paramDouble)
  {
    this.m_sTransactionID = paramString;
    this.m_dTotal = paramDouble;
    resetState();
    this.m_jHolderName.activate();
  }

  private void resetState()
  {
    this.m_notifier.setStatus(false, false);
    this.m_jHolderName.setText(null);
    this.m_jCardNumber.setText(null);
    this.m_jExpirationDate.setText(null);
  }

  public PaymentInfoMagcard getPaymentInfoMagcard()
  {
    if (this.m_dTotal > 0.0D)
      return new PaymentInfoMagcard(this.m_jHolderName.getText(), this.m_jCardNumber.getText(), this.m_jExpirationDate.getText(), null, null, null, this.m_sTransactionID, this.m_dTotal);
    return new PaymentInfoMagcardRefund(this.m_jHolderName.getText(), this.m_jCardNumber.getText(), this.m_jExpirationDate.getText(), null, null, null, this.m_sTransactionID, this.m_dTotal);
  }

  private boolean isValidHolder()
  {
    return (this.m_jHolderName.getText() != null) && (!this.m_jHolderName.getText().equals(""));
  }

  private boolean isValidCardNumber()
  {
    return (LuhnAlgorithm.checkCC(this.m_jCardNumber.getText())) && (this.m_jCardNumber.getText().length() > 13) && (this.m_jCardNumber.getText().length() < 20);
  }

  private boolean isValidExpirationDate()
  {
    return (this.m_jExpirationDate.getText() != null) && (this.m_jExpirationDate.getText().length() == 4);
  }

  private void initComponents()
  {
    this.jPanel2 = new JPanel();
    this.jPanel1 = new JPanel();
    this.m_jKeys = new JEditorKeys();
    this.jPanel4 = new JPanel();
    this.m_jCardNumber = new JEditorStringNumber();
    this.m_jExpirationDate = new JEditorStringNumber();
    this.m_jHolderName = new JEditorString();
    this.jLabel8 = new JLabel();
    this.jLabel6 = new JLabel();
    this.jLabel7 = new JLabel();
    this.jLabel2 = new JLabel();
    this.jPanel5 = new JPanel();
    this.jLabel1 = new JLabel();
    setLayout(new BorderLayout());
    this.jPanel2.setLayout(new BorderLayout());
    this.jPanel1.setLayout(new BoxLayout(this.jPanel1, 1));
    this.jPanel1.add(this.m_jKeys);
    this.jPanel2.add(this.jPanel1, "North");
    add(this.jPanel2, "East");
    this.jLabel8.setText(AppLocal.getIntString("label.cardholder"));
    this.jLabel6.setText(AppLocal.getIntString("label.cardnumber"));
    this.jLabel7.setText(AppLocal.getIntString("label.cardexpdate"));
    this.jLabel2.setFont(new Font("Dialog", 0, 10));
    this.jLabel2.setText("MMYY");
    GroupLayout localGroupLayout = new GroupLayout(this.jPanel4);
    this.jPanel4.setLayout(localGroupLayout);
    localGroupLayout.setHorizontalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addGap(20, 20, 20).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel8, -2, 90, -2).addComponent(this.m_jHolderName, -2, 180, -2)).addGroup(localGroupLayout.createSequentialGroup().addComponent(this.jLabel6, -2, 90, -2).addComponent(this.m_jCardNumber, -2, 180, -2)).addGroup(localGroupLayout.createSequentialGroup().addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel7, -2, 120, -2).addGroup(localGroupLayout.createSequentialGroup().addGap(90, 90, 90).addComponent(this.m_jExpirationDate, -2, 110, -2))).addGap(4, 4, 4).addComponent(this.jLabel2))).addGap(60, 60, 60)));
    localGroupLayout.setVerticalGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout.createSequentialGroup().addGap(20, 20, 20).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel8).addComponent(this.m_jHolderName, -2, -1, -2)).addGap(5, 5, 5).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel6).addComponent(this.m_jCardNumber, -2, -1, -2)).addGap(5, 5, 5).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel7).addGroup(localGroupLayout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(this.jLabel2).addComponent(this.m_jExpirationDate, -2, -1, -2)))));
    add(this.jPanel4, "Center");
    this.jLabel1.setText(AppLocal.getIntString("message.paymentgatewaytype"));
    this.jPanel5.add(this.jLabel1);
    add(this.jPanel5, "North");
  }

  private class RecalculateName
    implements PropertyChangeListener
  {
    private RecalculateName()
    {
    }

    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      boolean bool = (PaymentPanelType.this.isValidHolder()) && (PaymentPanelType.this.isValidCardNumber()) && (PaymentPanelType.this.isValidExpirationDate());
      PaymentPanelType.this.m_notifier.setStatus(bool, bool);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.PaymentPanelType
 * JD-Core Version:    0.6.0
 */